+2005-08-16 Øyvind Kolås <pippin@gimp.org>
+
+ * babl/babl-component.c: (component_new, each_babl_component_destroy) allocate
+ larger chunk, (babl_component_new) removed Babl* switch,
+ * babl/babl-conversion.c: (conversion_new): removed superflous runtime
+ warnings.
+ * babl/babl-fish.c: (babl_fish_process): reindent, added assert for
+ instance.
+ * babl/babl-image.c: (image_new, babl_image_new): reindent,
+ , (babl_image_new_from_linear): added asserts for parameters.
+ * babl/babl-model.c: (each_babl_model_destroy, model_new): allocate
+ larger chunk.
+ * babl/babl-pixel-format.c: (each_babl_pixel_format_destroy,
+ pixel_format_new): allocate larger chunk.
+ * babl/babl-sanity.c: (babl_conversion_source): removed FIXME comment
+ used for helper function just used to make code more readable.
+ * babl/babl-type.c: (each_babl_type_destroy, type_new): allocate
+ larger chunk.
+
2005-08-16 Øyvind Kolås <pippin@gimp.org>
* babl/babl-classes.h: (BablSampling) added static name.
{
babl_free (babl->component.from);
babl_free (babl->component.to);
- babl_free (babl->instance.name);
babl_free (babl);
return 0; /* continue iterating */
}
{
Babl *babl;
- babl = babl_calloc (sizeof (BablComponent), 1);
+ babl = babl_calloc (sizeof (BablComponent) +
+ strlen (name) + 1, 1);
+ babl->instance.name = (void *) babl + sizeof (BablComponent);
+ strcpy (babl->instance.name, name);
+
babl->class_type = BABL_COMPONENT;
babl->instance.id = id;
- babl->instance.name = babl_strdup (name);
babl->component.luma = luma;
babl->component.chroma = chroma;
babl->component.alpha = alpha;
babl_component_new (const char *name,
...)
{
- va_list varg;
+ va_list varg;
Babl *babl;
int id = 0;
int luma = 0;
{
Babl *babl = (Babl*)arg;
- switch (babl->class_type)
- {
- case BABL_TYPE:
- case BABL_INSTANCE:
- case BABL_COMPONENT:
- case BABL_PIXEL_FORMAT:
- case BABL_MODEL:
- case BABL_SAMPLING:
-
- case BABL_CONVERSION:
- case BABL_CONVERSION_TYPE:
- case BABL_CONVERSION_TYPE_PLANAR:
- case BABL_CONVERSION_MODEL_PLANAR:
- case BABL_CONVERSION_PIXEL_FORMAT:
- case BABL_CONVERSION_PIXEL_FORMAT_PLANAR:
- case BABL_FISH:
- case BABL_FISH_REFERENCE:
- case BABL_IMAGE:
- babl_log ("%s(): %s unexpected",
- __FUNCTION__, babl_class_name (babl->class_type));
- break;
- case BABL_SKY: /* shut up compiler */
- break;
- }
+ babl_log ("%s(): %s unexpected",
+ __FUNCTION__, babl_class_name (babl->class_type));
}
/* if we didn't point to a babl, we assume arguments to be strings */
+
else if (!strcmp (arg, "id"))
{
id = va_arg (varg, int);
chroma = 1;
}
-
else if (!strcmp (arg, "alpha"))
{
alpha = 1;
__FUNCTION__);
}
break;
- case BABL_SAMPLING:
- babl_log ("%s(): sampling conversions not implemented yet\n",
- __FUNCTION__);
- break;
- case BABL_COMPONENT:
- babl_log ("%s(): component conversions do not make sense (except perhaps for gamma correction)\n",
- __FUNCTION__);
- break;
case BABL_MODEL:
if (linear)
{
__FUNCTION__);
}
break;
-
case BABL_PIXEL_FORMAT:
if (linear)
{
}
break;
default:
+ babl_log ("%s(): %s unexpected",
+ __FUNCTION__, babl_class_name (babl->class_type));
break;
}
if (!babl)
#define BABL_MAX_BANDS 32
int
-babl_fish_process (BablFish *babl_fish,
- void *source,
- void *destination,
- int n)
+babl_fish_process (Babl *babl,
+ void *source,
+ void *destination,
+ int n)
{
- Babl *babl;
Babl *imageA;
Babl *imageB;
Babl *imageC;
- fooA = babl_malloc(sizeof (double) * n * 4);
- fooB = babl_malloc(sizeof (double) * n * 4);
+ fooA = babl_malloc(sizeof (double) * n * 4);
+ fooB = babl_malloc(sizeof (double) * n * 4);
- assert (babl_fish);
+ assert (babl);
assert (source);
assert (destination);
+ assert (babl->class_type == BABL_FISH ||
+ babl->class_type == BABL_FISH_REFERENCE);
- babl = (Babl *)babl_fish;
if (BABL_IS_BABL (source) ||
BABL_IS_BABL (destination))
{
return -1;
}
- ((BablConversion*)(babl->reference_fish.type_to_double))->function.linear(
+ babl->reference_fish.type_to_double->function.linear(
source,
fooA,
- n* ((BablPixelFormat*)(babl_fish->source))->bands
+ n* BABL(babl->fish.source)->pixel_format.bands
);
/* calculate planar representation of fooA, and fooB */
imageB = babl_image_new_from_linear (fooB, babl_model_id (BABL_RGBA));
/* transform fooA into fooB fooB is rgba double */
- ((BablConversion*)(babl->reference_fish.model_to_rgba))->function.planar(
+ babl->reference_fish.model_to_rgba->function.planar(
imageA->image.bands,
imageA->image.data,
imageA->image.pitch,
imageB = babl_image_new_from_linear (fooB, babl_model_id (BABL_RGBA));
imageC = babl_image_new_from_linear (fooA, BABL(BABL((babl->fish.destination))->pixel_format.model[0]));
- ((BablConversion*)(babl->reference_fish.rgba_to_model))->function.planar(
+ babl->reference_fish.rgba_to_model->function.planar(
imageB->image.bands,
imageB->image.data,
imageB->image.pitch,
n);
- ((BablConversion*)(babl->reference_fish.double_to_type))->function.linear(
- fooA, destination, n * ((BablPixelFormat*)(babl_fish->destination))->bands
- );
+ babl->reference_fish.double_to_type->function.linear(
+ fooA, destination, n * BABL(babl->fish.destination)->pixel_format.bands);
babl_free (imageB);
babl_free (imageC);
return 0;
}
-/*BABL_CLASS_TEMPLATE(BablFish, babl_fish, "BablFish")*/
-BABL_DEFINE_INIT(babl_fish)
-BABL_DEFINE_DESTROY(babl_fish)
-BABL_DEFINE_EACH(babl_fish)
+BABL_DEFINE_INIT (babl_fish)
+BABL_DEFINE_DESTROY (babl_fish)
+BABL_DEFINE_EACH (babl_fish)
{
babl_free (babl->pixel_format.from);
babl_free (babl->pixel_format.to);
- babl_free (babl->pixel_format.component);
- babl_free (babl->pixel_format.type);
- babl_free (babl->pixel_format.sampling);
- babl_free (babl->pixel_format.model);
- babl_free (babl->instance.name);
babl_free (babl);
return 0; /* continue iterating */
Babl *babl;
int band;
- babl = babl_calloc (sizeof (BablPixelFormat), 1);
-
+ /* allocate all memory in one chunk */
+ babl = babl_calloc (sizeof (BablPixelFormat) +
+ strlen (name) + 1 +
+ sizeof (BablModel*) * (bands+1) +
+ sizeof (BablComponent*) * (bands+1) +
+ sizeof (BablSampling*) * (bands+1) +
+ sizeof (BablType*) * (bands+1) +
+ sizeof (int) * (bands+1) +
+ sizeof (int) * (bands+1),1);
+
+ babl->instance.name = ((void *)babl) + sizeof (BablPixelFormat);
+ babl->pixel_format.model = ((void *)babl->instance.name) + strlen (name) + 1;
+ babl->pixel_format.component = ((void *)babl->pixel_format.model) + sizeof (BablModel*) * (bands+1);
+ babl->pixel_format.type = ((void *)babl->pixel_format.component) + sizeof (BablComponent*) * (bands+1);
+ babl->pixel_format.sampling = ((void *)babl->pixel_format.type) + sizeof (BablType*) * (bands+1);
+
babl->class_type = BABL_PIXEL_FORMAT;
babl->instance.id = id;
- babl->instance.name = babl_strdup (name);
+ strcpy (babl->instance.name, name);
babl->pixel_format.bands = bands;
babl->pixel_format.planar = planar;
- babl->pixel_format.model = babl_malloc (sizeof (BablModel*) * (bands+1));
- babl->pixel_format.component = babl_malloc (sizeof (BablComponent*) * (bands+1));
- babl->pixel_format.type = babl_malloc (sizeof (BablType*) * (bands+1));
- babl->pixel_format.sampling = babl_malloc (sizeof (BablSampling*) * (bands+1));
-
for (band=0; band < bands; band++)
{
babl->pixel_format.model[band] = model[band];
#include <string.h>
#include <stdarg.h>
+#include <assert.h>
#include "babl-internal.h"
#include "babl-image.h"
int *stride)
{
Babl *babl;
- int band;
-
- babl = babl_calloc (
- sizeof (BablImage) +
- sizeof (BablComponent*) * (bands+1) +
- sizeof (void*) * (bands+1) +
- sizeof (int) * (bands+1) +
- sizeof (int) * (bands+1),1);
-
+ int band;
+
+ /* allocate all memory in one chunk */
+ babl = babl_calloc (sizeof (BablImage) +
+ sizeof (BablComponent*) * (bands+1) +
+ sizeof (void*) * (bands+1) +
+ sizeof (int) * (bands+1) +
+ sizeof (int) * (bands+1),1);
babl->image.component = ((void *)babl) + sizeof (BablImage);
babl->image.data = ((void *)babl->image.component) + sizeof (BablComponent*) * (bands+1);
babl->image.pitch = ((void *)babl->image.data) + sizeof (void*) * (bands+1);
int offset=0;
int calc_pitch=0;
+
+ assert (format);
+ assert (format->class_type == BABL_PIXEL_FORMAT ||
+ format->class_type == BABL_MODEL);
switch (format->class_type)
{
}
break;
default:
- babl_log ("%s(): Eeek!", __FUNCTION__);
break;
}
...)
{
va_list varg;
- Babl *babl;
+ Babl *babl;
int bands = 0;
BablComponent *component [BABL_MAX_BANDS];
void *data [BABL_MAX_BANDS];
{
babl_free (babl->model.from);
babl_free (babl->model.to);
- babl_free (babl->model.component);
- babl_free (babl->instance.name);
babl_free (babl);
return 0; /* continue iterating */
}
Babl *babl;
int i;
- babl = babl_calloc (sizeof (BablModel), 1);
-
+ babl = babl_calloc (sizeof (BablModel) +
+ sizeof (BablComponent*) * (components+1) +
+ strlen (name) + 1, 1);
+ babl->instance.name = ((void*)babl) + sizeof (BablModel);
+ babl->model.component = ((void*)babl->instance.name) + strlen (name) + 1;
+
babl->class_type = BABL_MODEL;
babl->instance.id = id;
- babl->instance.name = babl_strdup (name);
babl->model.components = components;
- babl->model.component = babl_malloc (sizeof (BablComponent*) * (components+1));
+ strcpy (babl->instance.name, name);
for (i=0; i < components; i++)
{
{
babl_free (babl->pixel_format.from);
babl_free (babl->pixel_format.to);
- babl_free (babl->pixel_format.component);
- babl_free (babl->pixel_format.type);
- babl_free (babl->pixel_format.sampling);
- babl_free (babl->pixel_format.model);
- babl_free (babl->instance.name);
babl_free (babl);
return 0; /* continue iterating */
Babl *babl;
int band;
- babl = babl_calloc (sizeof (BablPixelFormat), 1);
-
+ /* allocate all memory in one chunk */
+ babl = babl_calloc (sizeof (BablPixelFormat) +
+ strlen (name) + 1 +
+ sizeof (BablModel*) * (bands+1) +
+ sizeof (BablComponent*) * (bands+1) +
+ sizeof (BablSampling*) * (bands+1) +
+ sizeof (BablType*) * (bands+1) +
+ sizeof (int) * (bands+1) +
+ sizeof (int) * (bands+1),1);
+
+ babl->instance.name = ((void *)babl) + sizeof (BablPixelFormat);
+ babl->pixel_format.model = ((void *)babl->instance.name) + strlen (name) + 1;
+ babl->pixel_format.component = ((void *)babl->pixel_format.model) + sizeof (BablModel*) * (bands+1);
+ babl->pixel_format.type = ((void *)babl->pixel_format.component) + sizeof (BablComponent*) * (bands+1);
+ babl->pixel_format.sampling = ((void *)babl->pixel_format.type) + sizeof (BablType*) * (bands+1);
+
babl->class_type = BABL_PIXEL_FORMAT;
babl->instance.id = id;
- babl->instance.name = babl_strdup (name);
+ strcpy (babl->instance.name, name);
babl->pixel_format.bands = bands;
babl->pixel_format.planar = planar;
- babl->pixel_format.model = babl_malloc (sizeof (BablModel*) * (bands+1));
- babl->pixel_format.component = babl_malloc (sizeof (BablComponent*) * (bands+1));
- babl->pixel_format.type = babl_malloc (sizeof (BablType*) * (bands+1));
- babl->pixel_format.sampling = babl_malloc (sizeof (BablSampling*) * (bands+1));
-
for (band=0; band < bands; band++)
{
babl->pixel_format.model[band] = model[band];
}
-
-
-/* FIXME: these should be moved to babl-conversion.c */
-
-static Babl *babl_conversion_source (Babl *babl)
+static Babl *babl_conversion_source (Babl *babl)
{
return (Babl *)babl->conversion.source;
}
each_babl_type_destroy (Babl *babl,
void *data)
{
- babl_free (babl->instance.name);
babl_free (babl->type.from);
babl_free (babl->type.to);
babl_free (babl);
assert (bits != 0);
assert (bits % 8 == 0);
- babl = babl_calloc (sizeof (BablType), 1);
+ babl = babl_calloc (sizeof (BablType) + strlen (name) + 1, 1);
+ babl->instance.name = (void*) babl + sizeof (BablType);
babl->class_type = BABL_TYPE;
babl->instance.id = id;
- babl->instance.name = babl_strdup (name);
+ strcpy (babl->instance.name, name);
babl->type.bits = bits;
return babl;